Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
"if [ -z $variable ]" in a shell script is not recognising my variable

When I run the following script it keeps defaulting to the else statement and I'm not sure why. I have even included an echo $workflow which showed me the name that I was expecting to see but it still keeps defaulting to the else statement.

I've tried including an export namecheck=$workflow to see if that was the issue but it still gave the same end result

#!/bin/sh

read -p "Enter the workflow name: " workflowName

workflowName=${workflowName}

curl --request GET --url https://website.com > workflowjson.txt

workflow=$(jq -r .metadata.name workflowjson.txt)

echo $workflow

if [ -z "$workflow" ] then
    echo "Workflow is Valid" 
else
    echo "Workflow is not valid" 
fi
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

man test shows

-z STRING the length of STRING is zero

The code outputs Workflow is Valid when the workflow is empty.

Switch the then and else parts, or negate the condition (use -n instead of -z).

over 4 years ago · Santiago Trujillo Report

0

try taking the quotes out around workflow and put then in a separate line

if [ -z $workflow ]
then
  echo "Workflow is Valid" 
else
  echo "Workflow is not valid"
fi
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!